//
//  FourViewController.m
//  项目A --半糖
//
//  Created by romana on 16/5/16.
//  Copyright © 2016年 romana. All rights reserved.
//

#import "FourViewController.h"
#import "AdviceViewController.h"
#import <DKNightVersion.h>
#import "MyCollecgViewController.h"
#import "UIImageView+WebCache.h"

#import "BaseView.h"
#import "BaseLabel.h"

#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

@interface FourViewController ()

@property(nonatomic,strong)BaseLabel *secondRightLabel;

@end

@implementation FourViewController

-(void)viewWillAppear:(BOOL)animated{

    //  获取缓存大小
    NSUInteger size = [[SDImageCache sharedImageCache] getSize];
    float cacheSize = size / 1024.0 / 1024.0;
    
    self.secondRightLabel.text = [NSString stringWithFormat:@"%.2fM",cacheSize];


}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"设置";
    
//    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 200)];
//    headView.backgroundColor = [UIColor yellowColor];
   
    //上方图片
    UIImageView *headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, WIDTH, 250 + 55)];
    headImageView.backgroundColor = [UIColor yellowColor];
    headImageView.image = [UIImage imageNamed:@"u=2564972670,663754516&fm=21&gp=0.jpg"];
    [self.view addSubview:headImageView];
    
    UIView *gapView = [[UIView alloc] initWithFrame:CGRectMake(0, 250 + 64 + 55
, WIDTH, 5)];
    gapView.backgroundColor = [UIColor grayColor];
    [self.view addSubview:gapView];
    
//    //第一个view
//    BaseView *FirstView = [[BaseView alloc] initWithFrame:CGRectMake(0, 250 + 64 + 5, WIDTH, 55)];
//    FirstView.backgroundColor = [UIColor whiteColor];
//    [self.view addSubview:FirstView];
//    
//    UIImageView *firstLeftImageV = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 30, 30)];
//    firstLeftImageV.image = [UIImage imageNamed:@"user"];
//    firstLeftImageV.backgroundColor = [UIColor clearColor];
//    [FirstView addSubview:firstLeftImageV];
//    
//    BaseLabel *FirstMidLabel = [[BaseLabel alloc] initWithFrame:CGRectMake(50, 0, WIDTH - 50, 50)];
//    FirstMidLabel.backgroundColor = [UIColor clearColor];
//    FirstMidLabel.text = @"用户登录";
//    
//    [FirstView addSubview:FirstMidLabel];
//    
//    UIImageView *FirstRightImageV = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH - 50, 10, 30, 30)];
//    FirstRightImageV.image = [UIImage imageNamed:@"jiantou"];
//    FirstRightImageV.backgroundColor = [UIColor clearColor];
//    [FirstView addSubview:FirstRightImageV];
//    
//    UIView *FirstGapView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, WIDTH, 5)];
//    FirstGapView.backgroundColor = [UIColor grayColor];
//    [FirstView addSubview:FirstGapView];
    
    //点击手势(轻拍手势)
    
  //  UITapGestureRecognizer *Logtap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(LogtapAction)];
    
  //  [FirstView addGestureRecognizer:Logtap];
    
    //第二个view
    BaseView *SecondView = [[BaseView alloc] initWithFrame:CGRectMake(0, 250 + 64 + 5 + 55, WIDTH, 55)];
    SecondView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:SecondView];
    
    UIImageView *SecondLeftImageV = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 30, 30)];
    SecondLeftImageV.image = [UIImage imageNamed:@"lajitong"];
    SecondLeftImageV.backgroundColor = [UIColor clearColor];
    [SecondView addSubview:SecondLeftImageV];
    
    BaseLabel *SecondMidLabel = [[BaseLabel alloc] initWithFrame:CGRectMake(50, 0, WIDTH - 70, 50)];
    SecondMidLabel.backgroundColor = [UIColor whiteColor];
    SecondMidLabel.text = @"清理缓存";
    [SecondView addSubview:SecondMidLabel];
    
   
  //  获取缓存大小
     // NSUInteger size = [[SDImageCache sharedImageCache] getSize];
    //    float cacheSize = size / 1024.0 / 1024.0;
    //清除缓存label
    BaseLabel *secondRightLabel = [[BaseLabel alloc] initWithFrame:CGRectMake(WIDTH - 70, 10, 60, 30)];
     //      secondRightLabel.text = [NSString stringWithFormat:@"%.2fM",cacheSize];
    secondRightLabel.backgroundColor = [UIColor whiteColor];
    self.secondRightLabel = secondRightLabel;
    
    [SecondView addSubview:secondRightLabel];
    
    //点击手势(轻拍手势)
    
    UITapGestureRecognizer *Logtap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(LogtapAction:)];
    
      [SecondView addGestureRecognizer:Logtap];
    
    
    

    UIView *SecondGapView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, WIDTH, 5)];
    SecondGapView.backgroundColor = [UIColor grayColor];
    [SecondView addSubview:SecondGapView];
    
    //第三个view
    BaseView *ThirdView = [[BaseView alloc] initWithFrame:CGRectMake(0, 250 + 64 + 5 + 110, WIDTH, 55)];
    ThirdView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:ThirdView];
    
    UIImageView *ThirdLeftImageV = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 30, 30)];
    ThirdLeftImageV.image = [UIImage imageNamed:@"moon"];
    ThirdLeftImageV.backgroundColor = [UIColor clearColor];
    [ThirdView addSubview:ThirdLeftImageV];
    
    BaseLabel *ThirdMidLabel = [[BaseLabel alloc] initWithFrame:CGRectMake(50, 0, WIDTH - 100, 50)];
    ThirdMidLabel.backgroundColor = [UIColor whiteColor];
    ThirdMidLabel.text = @"夜间模式";
    [ThirdView addSubview:ThirdMidLabel];

    
    UIView *ThirdRightImageV = [[UIView alloc] initWithFrame:CGRectMake(WIDTH - 100, 0, 100, 50)];
    ThirdRightImageV.backgroundColor = [UIColor clearColor];
    [ThirdView addSubview:ThirdRightImageV];
    
    UIButton *DNbutton = [UIButton buttonWithType:UIButtonTypeCustom];
    DNbutton.frame = CGRectMake(35, 5, 40, 40);
    DNbutton.backgroundColor = [UIColor clearColor];
    [DNbutton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [DNbutton setBackgroundImage:[UIImage imageNamed:@"night"] forState:UIControlStateNormal];
    [ThirdRightImageV addSubview:DNbutton];
    
    
    
//    //UISwitch 中的frame中宽度 和高度是无效的,系统使用默认的size
//    UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(35 , 10, 50, 40)];
//    [ThirdRightImageV addSubview:mySwitch];
//    
//    //设置开关开启时候的颜色
//    mySwitch.onTintColor = [UIColor greenColor];
//    //设置开关的风格颜色
//    mySwitch.tintColor = [UIColor grayColor];
//    //设置开关的按钮颜色
//   //   mySwitch.thumbTintColor = [UIColor orangeColor];
//    //设置开关的初始状态(默认为no)
//    mySwitch.on = NO;
//    //加一个响应方法
//    [mySwitch addTarget:self action:@selector(switchAction) forControlEvents:UIControlEventValueChanged];
    
    UIView *ThirdGapView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, WIDTH, 5)];
    ThirdGapView.backgroundColor = [UIColor grayColor];
    [ThirdView addSubview:ThirdGapView];
    
    //第四个view
    BaseView *FourthView = [[BaseView alloc] initWithFrame:CGRectMake(0, 250 + 64 + 170, WIDTH, 55)];
    FourthView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:FourthView];
    
    UIImageView *FourthLeftImageV = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 30, 30)];
    FourthLeftImageV.image = [UIImage imageNamed:@"advice"];
    FourthLeftImageV.backgroundColor = [UIColor clearColor];
    [FourthView addSubview:FourthLeftImageV];
    
    BaseLabel *FourthMidLabel = [[BaseLabel alloc] initWithFrame:CGRectMake(50, 0, WIDTH - 50, 50)];
    FourthMidLabel.backgroundColor = [UIColor whiteColor];
    FourthMidLabel.text = @"意见反馈";
    [FourthView addSubview:FourthMidLabel];
    
    UIImageView *FourthRightImageV = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH - 50, 10, 30, 30)];
       FourthRightImageV.image = [UIImage imageNamed:@"jiantou"];
    FourthRightImageV.backgroundColor = [UIColor clearColor];
    [FourthView addSubview:FourthRightImageV];
    
    //点击手势(轻拍手势)
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
    
    [FourthView addGestureRecognizer:tap];
    
    UIView *FourthGapView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, WIDTH, 5)];
    FourthGapView.backgroundColor = [UIColor grayColor];
    [FourthView addSubview:FourthGapView];
    
    //第五个view
    BaseView *FifthView = [[BaseView alloc] initWithFrame:CGRectMake(0, 250 + 64 + 170 + 55, WIDTH, 55)];
    FifthView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:FifthView];
    
    UIImageView *FifthLeftImageV = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 30, 30)];
    FifthLeftImageV.image = [UIImage imageNamed:@"collection"];
    
    FifthLeftImageV.backgroundColor = [UIColor clearColor];
    [FifthView addSubview:FifthLeftImageV];
    
    BaseLabel *FifthMidLabel = [[BaseLabel alloc] initWithFrame:CGRectMake(50, 0, WIDTH - 50, 50)];
    FifthMidLabel.backgroundColor = [UIColor whiteColor];
    FifthMidLabel.text = @"我的收藏";
    [FifthView addSubview:FifthMidLabel];
    
    UIImageView *FifthRightImageV = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH - 50, 10, 30, 30)];
    FifthRightImageV.backgroundColor = [UIColor clearColor];
       FifthRightImageV.image = [UIImage imageNamed:@"jiantou"];
    [FifthView addSubview:FifthRightImageV];
    
    UIView *FifthGapView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, WIDTH, 5)];
    FifthGapView.backgroundColor = [UIColor grayColor];
    [FifthView addSubview:FifthGapView];
    
    //点击手势(轻拍手势)
    
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fifthtapAction)];
    
    [FifthView addGestureRecognizer:tap2];
    
    
    
    
    
    
    
    
    // Do any additional setup after loading the view.
}

-(void)LogtapAction:(CGFloat)cacheSize{

    UIAlertController *alerAction = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"确定删除缓存吗?"] message:nil preferredStyle:UIAlertControllerStyleAlert];
    [alerAction addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    [alerAction addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [[SDImageCache sharedImageCache] clearDisk];
        //  获取缓存大小
        NSUInteger size = [[SDImageCache sharedImageCache] getSize];
        float cacheSize = size / 1024.0 / 1024.0;
        
        self.secondRightLabel.text = [NSString stringWithFormat:@"%.2fM",cacheSize];
        //  [self removedChace];
     //   [self.tableView reloadData];
        
    }]];
    
    [self presentViewController:alerAction animated:YES completion:nil];
    
    



}
//
//-(void)LogtapAction{
//
//    //登录第二步
//    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];
//    
//    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
//        
//        //          获取微博用户名、uid、token等
//        
//        if (response.responseCode == UMSResponseCodeSuccess) {//登录成功
//            
//            UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToSina];
//            
//            NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
//            
//            
//            //登录第三步 ：在登录成功后 获取用户信息
//            
//            //获取accestoken以及新浪用户信息，得到的数据在回调Block对象形参respone的data属性
//            [[UMSocialDataService defaultDataService] requestSnsInformation:UMShareToSina  completion:^(UMSocialResponseEntity *response){
//                NSLog(@"SnsInformation is %@",response.data);
//            }];
//            
//            
//            
//        }});
//
//
//
//
//
//}

//夜间模式button
-(void)buttonAction:(UIButton *)button{

    if ([self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) {
        NSLog(@"白天");
         [button setBackgroundImage:[UIImage imageNamed:@"night"] forState:UIControlStateNormal];
        [self.dk_manager dawnComing];
    } else {
        NSLog(@"晚上");
         [button setBackgroundImage:[UIImage imageNamed:@"day"] forState:UIControlStateNormal];
        
        [self.dk_manager nightFalling];
    }



}

//收藏跳转
-(void)fifthtapAction{

    MyCollecgViewController *myCollectVC = [[MyCollecgViewController alloc] init];
    [self.navigationController pushViewController:myCollectVC animated:YES];



}


//轻拍跳转
-(void)tapAction{

  //  NSLog(@"2222");
    AdviceViewController *adviceVC = [[AdviceViewController alloc] init];
    [self.navigationController pushViewController:adviceVC animated:YES];




}



//-(void)switchAction{
//
//    NSLog(@"1111");
//
//}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
